

Public Class RequestContext


    Protected Shared Function GetQueryDecimal(ByVal param As String) As Decimal
        If HttpContext.Current.Request.QueryString(param) Is Nothing Then
            Return 0
        Else
            Try
                Return Decimal.Parse(HttpContext.Current.Request.QueryString(param))
            Catch ex As Exception
                Return 0
            End Try
        End If
    End Function

    Protected Shared Function GetQueryInt(ByVal param As String) As Integer
        If HttpContext.Current.Request.QueryString(param) Is Nothing Then
            Return 0
        Else
            Try
                Return Integer.Parse(HttpContext.Current.Request.QueryString(param))
            Catch ex As Exception
                Return 0
            End Try
        End If
    End Function

    Protected Shared Function GetQueryString(ByVal param As String) As String
        If HttpContext.Current.Request.QueryString(param) Is Nothing Then
            Return ""
        Else
            Return HttpContext.Current.Request.QueryString(param)
        End If
    End Function

    Public Shared ReadOnly Property ShippingStatusReportID() As Integer
        Get
            Return GetQueryInt("id")
        End Get
    End Property

    Public Shared ReadOnly Property Changed() As Boolean
        Get
            Return Convert.ToBoolean(GetQueryInt("changed"))
        End Get
    End Property

    Public Shared ReadOnly Property RefreshParent() As Boolean
        Get
            Return Convert.ToBoolean(GetQueryInt("rp"))
        End Get
    End Property

    Public Shared ReadOnly Property ChainOfID() As String
        Get
            Return GetQueryString("ids")
        End Get
    End Property

    Public Shared ReadOnly Property SelectedIDs() As ArrayList
        Get
            Return New ArrayList(ChainOfID.Split(","c))
        End Get
    End Property

    Public Shared Property CurrentUser() As MIMS.WRS.Entities.USER
        Get
            Return CType(HttpContext.Current.Session("CurrentUserNewObject"), MIMS.WRS.Entities.USER)
        End Get
        Set(ByVal Value As MIMS.WRS.Entities.USER)
            HttpContext.Current.Session("CurrentUserNewObject") = Value
        End Set
    End Property


    Public Shared Property CurrentDestinationCountry() As Integer
        Get
            If (HttpContext.Current.Session("CurrentDestinationCountry") Is Nothing) Then
                Return 0
            End If
            Return CType(HttpContext.Current.Session("CurrentDestinationCountry"), Integer)
        End Get
        Set(ByVal Value As Integer)
            HttpContext.Current.Session("CurrentDestinationCountry") = Value
        End Set
    End Property

    Public Shared ReadOnly Property OfficeName() As String
        Get
            Return CurrentOffice.OfficeName
        End Get
    End Property

    Public Shared Property CurrentOffice() As MIMS.WRS.Entities.Office
        Get
            Return CType(HttpContext.Current.Session("OfficeObject"), MIMS.WRS.Entities.Office)
        End Get
        Set(ByVal Value As MIMS.WRS.Entities.Office)
            HttpContext.Current.Session("OfficeObject") = Value
        End Set
    End Property

    Public Shared ReadOnly Property OrderType() As Int32
        Get
            Return GetQueryInt("type")
        End Get
    End Property

    Public Shared ReadOnly Property SortType() As EPOAndContainerScheduleSorting
        Get
            Return CType(GetQueryInt("sort"), EPOAndContainerScheduleSorting)
        End Get
    End Property

    Public Shared ReadOnly Property BOSortType() As EBOSorting
        Get
            Return CType(GetQueryInt("sort"), EBOSorting)
        End Get
    End Property

    Public Shared ReadOnly Property BulkOrderID() As Integer
        Get
            Return GetQueryInt("id")
        End Get
    End Property

    Public Shared ReadOnly Property SupplierCode() As String
        Get
            Return GetQueryString("sup")
        End Get
    End Property

    Public Shared ReadOnly Property ShippingLineID() As Integer
        Get
            Return GetQueryInt("slid")
        End Get
    End Property

    Public Shared ReadOnly Property CatalogID() As Integer
        Get
            Return GetQueryInt("catid")
        End Get
    End Property

    Public Shared ReadOnly Property ResponsibleID() As Integer
        Get
            Return GetQueryInt("respid")
        End Get
    End Property

    Public Shared ReadOnly Property TerritoryID() As Integer
        Get
            Return GetQueryInt("teid")
        End Get
    End Property

    Public Shared ReadOnly Property CountryID() As Integer
        Get
            Return GetQueryInt("countryid")
        End Get
    End Property

    Public Shared ReadOnly Property ConPointID() As Integer
        Get
            Return GetQueryInt("cpid")
        End Get
    End Property

    Public Shared ReadOnly Property ConPointIDForBODetail() As Integer
        Get
            Return GetQueryInt("conPointID")
        End Get
    End Property

    Public Shared Property ConPointIDForBODetailSS() As Integer
        Get
            Try
                Return Convert.ToInt32(HttpContext.Current.Session("ConPointIDForBODetailSS"))
            Catch ex As Exception
                Return 0
            End Try
        End Get
        Set(ByVal Value As Integer)
            HttpContext.Current.Session("ConPointIDForBODetailSS") = Value
        End Set
    End Property



    Public Shared ReadOnly Property IDSSortID() As Integer
        Get
            Return GetQueryInt("id")
        End Get
    End Property

    Public Shared ReadOnly Property TabID() As Integer
        Get
            Return GetQueryInt("tabid")
        End Get
    End Property

    ' 0: incomplete
    ' 1: completed order
    Public Shared ReadOnly Property BulkOrderType() As Integer
        Get
            Return GetQueryInt("botype")
        End Get
    End Property

    ' 0: incomplete
    ' 1: completed order
    Public Shared ReadOnly Property POType() As Integer
        Get
            Return GetQueryInt("potype")
        End Get
    End Property

    Public Shared ReadOnly Property Owner() As Integer
        Get
            Return GetQueryInt("owner")
        End Get
    End Property

    Public Shared ReadOnly Property OwnerID() As Integer
        Get
            Return GetQueryInt("ownerid")
        End Get
    End Property


    Public Shared ReadOnly Property BOType() As Integer
        Get
            Return GetQueryInt("type")
        End Get
    End Property

    Public Shared ReadOnly Property Target() As Integer
        Get
            Return GetQueryInt("target")
        End Get
    End Property

    Public Shared ReadOnly Property ReportType() As Integer
        Get
            Return GetQueryInt("rt")
        End Get
    End Property

    Public Shared ReadOnly Property Discount() As Decimal
        Get
            Return GetQueryDecimal("discount")
        End Get
    End Property

    Public Shared ReadOnly Property ShowFOB() As Boolean
        Get
            Return Convert.ToBoolean(GetQueryInt("showfob"))
        End Get
    End Property

    Public Shared ReadOnly Property Quantity() As Integer
        Get
            Return GetQueryInt("qty")
        End Get
    End Property

    Public Shared ReadOnly Property NotAvailInUSA() As Boolean
        Get
            Return Convert.ToBoolean(GetQueryInt("naUSA"))
        End Get
    End Property

    Public Shared ReadOnly Property SelectedSupplier() As String
        Get
            If Not (HttpContext.Current.Request.Cookies(BulkOrderList.SELECTED_SUPPLIER_COOKIE_NAME) Is Nothing) Then
                Dim supplierNo As String = HttpContext.Current.Request.Cookies(BulkOrderList.SELECTED_SUPPLIER_COOKIE_NAME).Value
                Return supplierNo
            Else
                Return ""
            End If
        End Get
    End Property

    Public Shared ReadOnly Property DoReport() As Boolean
        Get
            Return Convert.ToBoolean(GetQueryInt("dorpt"))
        End Get
    End Property

    Public Shared ReadOnly Property SalesOrder() As Integer
        Get
            Dim so As Integer = GetQueryInt("so")
            If so <= 0 Then
                Return -1
            Else
                Return so
            End If
        End Get
    End Property

    Public Shared ReadOnly Property OfficeID() As Integer
        Get
            If HttpContext.Current.Request.QueryString("oid") <> Nothing Then
                Return GetQueryInt("oid")
            Else
                Return RequestContext.CurrentUser.ActiveOfficeID
            End If
        End Get
    End Property

    Public Shared ReadOnly Property UserID() As Integer
        Get
            Dim val As Integer = GetQueryInt("uid")
            If val <= 0 Then
                Return -1
            Else
                Return val
            End If
        End Get
    End Property

    Public Shared ReadOnly Property ProductCode() As String
        Get
            Return GetQueryString("procode")
        End Get
    End Property


    Public Shared ReadOnly Property CurrencyID() As Integer
        Get
            Return GetQueryInt("currid")
        End Get
    End Property

    Public Shared Property ShoppingUser() As MIMS.WRS.Entities.USER
        Get
            Return CType(HttpContext.Current.Session("ShoppingUser"), MIMS.WRS.Entities.USER)
        End Get
        Set(ByVal Value As MIMS.WRS.Entities.USER)
            HttpContext.Current.Session("ShoppingUser") = Value
        End Set
    End Property
End Class


Public Class ShoppingConext

    Public Shared Property ShopingUserId() As Integer
        Get
            Try
                Return Convert.ToInt32(HttpContext.Current.Session(Constant.SS_SHOPPING_USER))
            Catch ex As Exception
                Return 0
            End Try
        End Get
        Set(ByVal Value As Integer)
            HttpContext.Current.Session(Constant.SS_SHOPPING_USER) = Value
        End Set
    End Property

    Public Shared Property ShopingUserEmail() As String
        Get
            Try
                Return Convert.toString(HttpContext.Current.Session(Constant.SS_SHOPPING_USER_EMAIL))
            Catch ex As Exception
                Return ""
            End Try
        End Get
        Set(ByVal Value As String)
            HttpContext.Current.Session(Constant.SS_SHOPPING_USER_EMAIL) = Value
        End Set
    End Property

    Public Shared Property ShopingSelectedConsolidation() As Integer
        Get
            Try
                Return Convert.ToInt32(HttpContext.Current.Session(Constant.SS_SELECTED_CONPOINT_ID))
            Catch ex As Exception
                Return 0
            End Try
        End Get
        Set(ByVal Value As Integer)
            HttpContext.Current.Session(Constant.SS_SELECTED_CONPOINT_ID) = Value
        End Set
    End Property

    Public Shared Property ShoppingOrderId() As Integer
        Get
            Try
                Return Convert.ToInt32(HttpContext.Current.Session("ShoppingOrderId"))
            Catch ex As Exception
                Return 0
            End Try
        End Get
        Set(ByVal Value As Integer)
            HttpContext.Current.Session("ShoppingOrderId") = Value
        End Set
    End Property


End Class